﻿@using CleanArchitecture.Core.Helper
@using CleanArchitecture.Infrastructure.Models.Business.Advertises;
@model AdvertiseBannerModel
@{
    Layout = "_BackendLayout";
    ViewData["Title"] = ViewBag.PageTitle as string;
    int currentSystemModuleId = ViewBag.CurrentSystemModuleId;
    AdvertiseBannerSearchModel searchModel = Model.CustomProperties["AdvertiseBannerSearchModel"] as AdvertiseBannerSearchModel ?? null;
}
@section cssstyles {
    <style type="text/css">
        body {
            margin: 20px !important;
            display: flex;
            flex: auto;
            flex-direction: column;
            min-height: 0;
            background: #f0f2f5;
        }

        .backendadvertisemanage {
            width: 100% !important;
            height: 100%;
            background-color: #fff;
            margin: 0 !important;
            padding: 10px 2px;
        }
    </style>
}
<div class="backendadvertisemanage layui-main">
    <form class="layui-form">
        <fieldset class="layui-elem-field">
            <div class="layui-field-box pagebuttongroup">
                @await Component.InvokeAsync("PageButton")
            </div>
        </fieldset>

        <table id="advertisemanagetable" lay-filter="advertisemanagetable"></table>
    </form>
</div>
<input type="text" class="layui-hide" id="currentSystemModuleId" value="@currentSystemModuleId" />
@await Component.InvokeAsync("RecordButton")

<!--显示方式-->
<script type="text/html" id="advbannerdisplaytypeTpl">
    {{#  if(d.AdvBannerDisplayType == 1){ }}
    <span>PC端展示</span>
    {{#  } else { }}
    <span>手机端展示</span>
    {{#  } }}
</script>

<!--广告类型 与后端定义一致-->
<script type="text/html" id="advbannertypeTpl">
    {{#  if(d.AdvBannerType === 1){ }}
    <span>轮播图列表</span>
    {{#  } else if(d.AdvBannerType === 2) { }}
    <span>友情链接(文字)</span>
    {{#  } else if(d.AdvBannerType === 3) { }}
    <span>友情链接(图片)</span>
    {{#  } else if(d.AdvBannerType === 4) { }}
    <span>固定位置单图</span>
    {{#  } else if(d.AdvBannerType === 5) { }}
    <span>图片栅格矩阵</span>
    {{#  } else { }}
    <span style="color: red;">未知类型</span>
    {{#  } }}
</script>

@section scripts{
    <script type="text/javascript">
        var advertisetableconfig = null;
        layui.use(['util'], function () {
            var util = layui.util;
            advertisetableconfig = {
                elem: '#advertisemanagetable',
                url: '/api/backend/business/advertisemanage/getadvertiselist',
                request: {
                    pageName: '@searchModel.nameof(p => p.Page)', //页码的参数名称，默认：page
                    limitName: '@searchModel.nameof(p => p.PageSize)' //每页数据量的参数名，默认：limit
                },
                limits: [@searchModel.AvailablePageSizes],
                limit:  @searchModel.PageSize,
                cols: [[
                    { type: "checkbox", width: 50, fixed: "left" },
                    { field: 'Id', hide: true, title: 'ID' },
                    { field: '@Model.nameof(p => p.AdvBannerName)', title: '@(ReflectionExtensions.GetPropertyDisplayName<AdvertiseBannerModel>(m => m.AdvBannerName))' },
                    { field: '@Model.nameof(p => p.AdvBannerDisplayType)', title: '@(ReflectionExtensions.GetPropertyDisplayName<AdvertiseBannerModel>(m => m.AdvBannerDisplayType))', templet: '#advbannerdisplaytypeTpl', width: 120 },
                    { field: '@Model.nameof(p => p.AdvBannerType)', title: '@(ReflectionExtensions.GetPropertyDisplayName<AdvertiseBannerModel>(m => m.AdvBannerType))', templet: '#advbannertypeTpl', width: 120 },
                    { field: '@Model.nameof(p => p.AdvBannerWidth)', title: '@(ReflectionExtensions.GetPropertyDisplayName<AdvertiseBannerModel>(m => m.AdvBannerWidth))', width: 100 },
                    { field: '@Model.nameof(p => p.AdvBannerHeight)', title: '@(ReflectionExtensions.GetPropertyDisplayName<AdvertiseBannerModel>(m => m.AdvBannerHeight))', width: 100 },
                    { field: '@Model.nameof(p => p.StartTime)', title: '@(ReflectionExtensions.GetPropertyDisplayName<AdvertiseBannerModel>(m => m.StartTime))', templet: function (d) { return d.StartTime === null ? "不限" : util.toDateString(d.StartTime, "yyyy-MM-dd"); } },
                    { field: '@Model.nameof(p => p.EndTime)', title: '@(ReflectionExtensions.GetPropertyDisplayName<AdvertiseBannerModel>(m => m.EndTime))', templet: function (d) { return d.EndTime === null ? "不限" : util.toDateString(d.EndTime, "yyyy-MM-dd"); } },
                    { title: '操作', minWidth: 100, templet: '#tableitemBars', fixed: "right", align: "center" }
                ]],
                parseData: function (res) { //res 即为原始返回的数据
                    return {
                        "code": res.state == 200 ? 0 : -1,      //解析接口状态
                        "msg": res.message,                     //解析提示文本
                        "count": res.data.RecordsTotal,         //解析数据长度
                        "data": res.data.Data                   //解析数据列表
                    };
                },
                page: true
            };
        });
    </script>
    <script src="~/js/backend/business/advertisemanage.min.js" charset="utf-8" asp-append-version="true"></script>
}
